package com.startasone.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.startasone.mapper.EmpMapper;
import com.startasone.pojo.Emp;
import com.startasone.pojo.PageBean;
import com.startasone.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;

    @Override
    public PageBean getByPage(Integer page, Integer pageSize, String name, Short gender, LocalDate start, LocalDate end) {
        PageHelper.startPage(page,pageSize);
        List<Emp> emps=empMapper.getByPage(name,gender,start,end);
        Page<Emp> p=(Page<Emp>)emps;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return  pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void insert(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id) {
        Emp emp=empMapper.getById(id);
        return emp;
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.getByUsernameAndPassword(emp);
    }

}
